package personnal.blogprinter;

import java.io.File;
import java.io.FileOutputStream;

import personnal.blogprinter.data.PostInfo;
import personnal.blogprinter.data.Settings;
import personnal.blogprinter.generator.HtmlPdfGenerator;

import com.thoughtworks.xstream.XStream;

public class PostInfoFileCreator {

	public static void main(String[] args) throws Exception {
		Settings settings = new Settings();
		settings.setUrl("http://mektoub.free.fr/blog/xmlrpc.php");
		settings.setUsername("admin");
		settings.setPassword("bx9mjj7n");
		settings.setFromMonth("2009-01");
		settings.setToMonth("2009-03");
//		settings.setProxyHost("webcache.groupe.generali.fr");
//		settings.setProxyPort(3128);
		WordpressClient client = new WordpressClient(settings);

		int postId = 168;

		PostInfo postInfo = client.getPostById( postId );
		XStream xstream = new XStream();
		FileOutputStream outputStream = new FileOutputStream("src/test/resources/PostInfo"+postId+".xml");
		outputStream.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n".getBytes("ISO-8859-1"));
		xstream.toXML(postInfo, outputStream);
		HtmlPdfGenerator generator = new HtmlPdfGenerator();
		generator.init(new File("target", "Post"+postId+".pdf"));
		generator.addPost(postInfo);
		generator.destroy();
	}

}
